<?php
class ContactController extends AppController
{
	var $name = 'Contact';
	var $uses = 'Contact';
	var $helpers = array('Html', 'Form', 'Javascript','Flash');
	var $components = array('Email', 'Session');
	
	function index(){
	  
		if(isset($this->data)) {
			$this->Contact->create($this->data);
		
			if($this->Contact->validates()){
			    
			    $this->data['Contact']['message'].= "\r\n".'---------------------------------------';
			    $this->data['Contact']['message'].= "\r\n".'Nombre:'.$this->data['Contact']['name'];
			    $this->data['Contact']['message'].= "\r\n".'Email:'.$this->data['Contact']['email'];
			    $this->data['Contact']['message'].= "\r\n".'Telefono:'.$this->data['Contact']['phone'];
				$this->data['Contact']['message'].= "\r\n".'Ciudad:'.$this->data['Contact']['city'];
			    $this->data['Contact']['message'].= "\r\n".'Direccion:'.$this->data['Contact']['direccion'];
				$this->data['Contact']['message'].= "\r\n".'Movil:'.$this->data['Contact']['celular'];
				$this->Email->to = 'info@publicidadyclasificados.com';//mail aqui
				$this->Email->replyTo = $this->data['Contact']['email'];
				$this->Email->from = $this->data['Contact']['name'].' <'.$this->data['Contact']['email'].'>';
				$this->Email->subject = 'Contacto desde Publicidad  y clasificados: '.' Contacto a travez de pagina web';
				//$this->Email->delivery = 'debug';
				if ($this->Email->send($this->data['Contact']['message'])) {
					$this->Session->setFlash('Mensaje Enviado');
					//$this->redirect('');
				} else {
					$this->Session->setFlash('No se pudo mandar el mail');
				}
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash('Por favor llene todos los campos');
				$this->redirect('/contacto');
			}
		}
	}
	
}
?>
